/**
 * @param {number[]} nums
 * @return {number}
 */
// 基本操作：一遍遍历
var maximumCount = function (nums) {
    let c1 = 0, c2 = 0
    for (let i = 0; i < nums.length; i++) {
        if (nums[i] < 0) {
            c1++
        } else if (nums[i] > 0) {
            c2++
        }
    }
    return Math.max(c1, c2)
};
// 进阶O(NlogN)
var maximumCount = function (nums) {
    let left = 0, right = nums.length - 1
    let firstIndex = -1, lastIndex = -1
    let middle;
    while (left <= right) {
        middle = (left + right) >>> 1
        if (nums[middle] < 0) {
            left = middle + 1
            firstIndex = middle
        } else if (nums[middle] >= 0) {
            right = middle - 1
        }
    }
    left = firstIndex + 1, right = nums.length - 1
    while(left <= right) {
        middle = (left + right) >>> 1
        if (nums[middle] > 0) {
            right = middle - 1
            lastIndex = middle
        } else if (nums[middle] === 0) {
           left = middle + 1
        }
    }
    if(firstIndex === -1 && lastIndex === -1) return 0 
    if(firstIndex === -1) return nums.length - lastIndex
    if(lastIndex === -1) return firstIndex + 1
    return Math.max(nums.length - lastIndex, firstIndex + 1)
};
console.log(maximumCount([-2,-1,-1,1,2,3]))
// console.log(maximumCount([0, 0, 0, 0, 0, 0, 0]))